<%= turbo_frame_tag promotion_rule do  %>
  <div class="card" id="<%= spree_dom_id(promotion_rule) %>">
    <div class="card-header d-flex justify-content-between align-items-center">
      <h5 class="card-title"><%= promotion_rule.human_name %></h5>

      <% if can?(:update, promotion_rule) || can?(:destroy, promotion_rule) %>
        <%= dropdown portal: false do %>
          <%= dropdown_toggle class: 'btn-light btn-sm px-1' do %>
            <%= icon('dots-vertical', class: 'mr-0') %>
          <% end %>
          <%= dropdown_menu do %>
            <%= link_to_with_icon 'pencil', Spree.t('actions.edit'), spree.edit_admin_promotion_rule_path(promotion_rule.promotion, promotion_rule), class: 'dropdown-item' if can?(:update, promotion_rule) %>
            <%= link_to_with_icon 'trash', Spree.t('actions.destroy'), spree.admin_promotion_rule_path(promotion_rule.promotion, promotion_rule), class: 'dropdown-item btn-danger', data: { turbo_method: :delete, turbo_confirm: Spree.t(:are_you_sure), turbo_frame: '_top' } if can?(:destroy, promotion_rule) %>
          <% end %>
        <% end %>
      <% end %>
    </div>
    <div class="card-body">
      <p class="text-muted"><%= promotion_rule.human_description %></p>

      <% if promotion_rule.preferences.present? %>
        <%= render 'spree/admin/shared/preferences', object: promotion_rule %>
      <% end %>

      <% if promotion_rule.respond_to?(:preferred_eligible_values) %>
        <div class="mt-3">
          <span><%= Spree.t(:option_values) %>:</span>
          <div class="d-flex flex-wrap gap-2">
            <% promotion_rule_option_values(promotion_rule.preferred_eligible_values).each do |value| %>
              <strong><%= value %></strong>
            <% end %>
          </div>
        </div>
      <% end %>

      <% if promotion_rule.respond_to?(:products) %>
        <div class="mt-3">
          <span><%= Spree.t(:products) %>:</span>
          <div class="d-flex flex-wrap gap-2">
            <% promotion_rule.products.pluck(:name).each do |product_name| %>
            <strong><%= product_name %></strong>
            <% end %>
          </div>
        </div>
      <% end %>

      <% if promotion_rule.respond_to?(:taxons) %>
        <div class="mt-3">
          <span><%= Spree.t(:taxons) %>:</span>
          <div class="d-flex flex-wrap gap-2">
            <% promotion_rule.taxons.pluck(:pretty_name).each do |taxon_name| %>
              <strong><%= taxon_name %></strong>
            <% end %>
          </div>
        </div>
      <% end %>

      <% if promotion_rule.respond_to?(:users) %>
        <div class="mt-3">
          <span><%= Spree.t(:users) %>:</span>
          <div class="d-flex flex-wrap gap-2">
            <% promotion_rule.users.pluck(:email).each do |user_email| %>
              <strong><%= user_email %></strong>
            <% end %>
          </div>
        </div>
      <% end %>
    </div>
  </div>
<% end %>
